package cn.wolfcode.trip.api.controller;

import cn.wolfcode.trip.base.domain.Chat;
import cn.wolfcode.trip.base.service.IChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/chat")
public class ChatController {
    @Autowired
    private IChatService chatService;
    /*
    * 查询聊天记录

    * */
    @GetMapping
    public Object listChatForHistory(Long sendId,Long receiveId){
        return chatService.listForChatHistory(sendId,receiveId);
    }
    /*
    * 添加聊天方法
    * */
    @PostMapping
    public void saveChat(Chat chat){
        chatService.save(chat);
    }
    /*
    * 查询未读状态
    * */
    @GetMapping("{receiveId}")
    public Object listChatState(@PathVariable Long receiveId){
        return chatService.listState(receiveId);
    }
    /*
     * 清除未读数
     * */
    @PutMapping
    public void updateChatState(Long receiveId){
         chatService.updateState(receiveId);
    }
    /*
     * 清除未读数
     * */
    @GetMapping("{receiveId}/num")
    public Integer getChatState(@PathVariable Long receiveId){
        return chatService.listStateNum(receiveId);
    }
}
